package cn.wolfcode.trip.base.domain;

import com.alibaba.druid.support.json.JSONUtils;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 *游记类
 */
@Setter
@Getter
public class Travel extends BaseDomain{

    //状态常量
    public static final int STATE_NORMAL =0;//草稿
    public static final int STATE_AUDIT =1;//待发布
    public static final int STATE_RELEASE =2;//发布
    public static final int STATE_REJECT =-1;//拒绝

    //标题
    private String title;

    //出行时间
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "GTM+8")
    private Date travelTime;

    //每人花销
    private String perExpends;
    //天数
    private Integer days;
    //和谁去
    private Integer person=1;
    //作者 --> 用户
    private User author;

    //创建时间
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd HH-mm-ss",timezone = "GTM+8")
    private Date createTime;

    //发布时间
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd HH-mm-ss",timezone = "GMT+8")
    private Date releaseTime;

    //是否公开
    private Boolean isPublic;
    //地区
    private Region place;
    //封面图url
    private String coverUrl;

    //最后更新时间
    @JsonFormat(pattern = "yyyy-MM-dd HH-mm-ss",timezone = "GMT+8")
    private Date lastUpdateTime;

    //状态
    private Integer state=STATE_NORMAL;
    //关联内容
    private Travelcontent travelContent;

    //json字符串
    public String getJsonString(){
        Map<String,Object> map=new HashMap<>();
        map.put("id",id);
        map.put("title",title);
        map.put("coverUrl",coverUrl);
        if(author!=null){
            map.put("authorId",author.getId());
        }
        return JSONUtils.toJSONString(map);
    }

    //获取状态的形容
    public String getStateName(){
        String str="";
        switch (state){
            case STATE_AUDIT:
                str="待发布";
                break;
            case STATE_RELEASE:
                str="已发布";
                break;
            case STATE_REJECT:
                str="拒绝";
                break;
            default:str ="草稿";
        }
        return str;
    }

    //获取人物的形容
    public String getPersonName(){
        String str="";
        switch (person){
            case 1:
                str="一个人的旅行";
                break;
            case 2:
                str="和父母";
                break;
            case 3:
                str="和朋友";
                break;
            case 4:
                str="和同事";
                break;
            case 5:
                str="和爱人";
                break;
            default:str ="和其他";
        }
        return str;
    }

}